﻿using System.Collections.Generic;
using System.Linq;
using ZilLion.Service.Core.DapperWrapper.SqlServer;
using ZilLion.Service.TaskPlatform.Domain.Entity;
using ZilLion.Service.TaskPlatform.Domain.Respository.Interface;

namespace ZilLion.Service.TaskPlatform.Domain.Respository.Sqlserver
{
    public class TaskModuleConfigRespository : SqlServerRespository<TaskModuleConfigEntity>,
        ITaskModuleConfigRespository
    {
        public TaskModuleConfigRespository()
        {
            Context = new TaskRunnerSqlserverContext();
        }

        public void AddModuleConfig(TaskModuleConfigEntity entity)
        {
            Add(entity);
        }

        public void MotifyModuleConfig(TaskModuleConfigEntity entity)
        {
            Modify(entity);
        }

        public IEnumerable<TaskModuleConfigEntity> GetAllModuleConfigs()
        {
            return GetList(@"select * from task_module_config");
        }

        public TaskModuleConfigEntity GetModuleConfigById(string taskmoduleId)
        {
            return
                GetList(@"select * from task_module_config where taskmoduleId=@taskmoduleId", new {taskmoduleId})
                    .FirstOrDefault();
        }

        public void RemoveModule(string taskmoduleId)
        {
            var entity = GetModuleConfigById(taskmoduleId);
            Remove(entity);
        }
    }
}